<template>
	<view>
		<data-loading :show="loadingShow"></data-loading>
		<view class="headerTop">
			<view class="userInfoBox" @click="goRoutePage('/packageA/pages/userinfo/userinfo')">
				<view class="leftBox">
					<image :src="userInfo.avatar" mode="aspectFill"></image>
					<view class="">
						<p>{{userInfo.name}}</p>
						<p>ID:{{userInfo.userId}}</p>
					</view>
				</view>
				<!-- #ifdef APP -->
				<view class="rightBox" v-if="userInfo.guest">
					恢复购买
				</view>
				<!-- #endif -->

			</view>
		</view>
		<view class="vipBox" v-if="vipShow">
			<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon8.png" class="vipBg" mode=""></image>
			<p>会员享受专属咨询通道，咨询无限制</p>
			<p @click="goRoute('/packageA/pages/vipCenter/vipCenter')" v-if="!isVip()">立即开通</p>
		</view>
		<view class="functionBox">
			<view class="items" @click="goRoutePage('/packageA/pages/reviewRecord/reviewRecord')">
				<view class="">
					<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon18.png" mode=""></image>
					<p>审查记录</p>
				</view>
				<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon2.png" mode=""></image>
			</view>
			<view class="items" @click="goRoutePage('/packageA/pages/writeRecord/writeRecord')">
				<view class="">
					<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon19.png" mode=""></image>
					<p>撰写记录</p>
				</view>
				<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon2.png" mode=""></image>
			</view>
			<view class="items" @click="goRoute('/packageA/pages/dialog/dialog')">
				<view class="">
					<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon1.png" mode=""></image>
					<p>AI法律助手</p>
				</view>
				<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon2.png" mode=""></image>
			</view>
			<!-- #ifdef MP -->
			<view class="items">
				<view class="">
					<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon5.png" mode=""></image>
					<p>联系客服</p>
				</view>
				<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon2.png" mode=""></image>
				<button open-type="contact"></button>
			</view>
			<view class="items">
				<view class="">
					<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon3.png" mode=""></image>
					<p>分享好友</p>
				</view>
				<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon2.png" mode=""></image>
				<button open-type="share"></button>
			</view>
			<!-- #endif -->
			<!-- <view class="items">
				<view class="">
					<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon4.png" mode=""></image>
					<p>关于我们</p>
				</view>
				<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon2.png" mode=""></image>
			</view> -->
			<view class="items" @click="goRoute('/packageA/pages/set/set')">
				<view class="">
					<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon7.png" mode=""></image>
					<p>设置</p>
				</view>
				<image src="http://cdn.yic3.cn/lawyer/mp-xhs/mine/icon2.png" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex'
	export default {

		data() {
			return {
				// userInfo: {},
				launchUserId: '',
				loadingShow: false,
				shareShow: true,
				payShow: true,
				content: '',
				vipShow: true,
			};
		},
		computed: {
			...mapState({
				userInfo: state => state.userInfo
			})
		},
		onLoad() {
			this.vipShow = uni.getStorageSync('config')['client.pay.enable']
			let service = 'client.center.weixin.service'
			console.log(uni.getStorageSync('config')['client.center.weixin.service']);
			if (!uni.getStorageSync('config')['client.center.weixin.service']) {
				this.functionList[0].show = false
			}
			// #ifdef MP-WEIXIN
			uni.preloadAssets({
				data: [{
					type: 'image',
					src: 'http://cdn.yic3.cn/lawyer/mp-xhs/mine/vipBg.png'
				}, {
					type: 'image',
					src: 'http://cdn.yic3.cn/lawyer/mp-xhs/guide/icon21.png'
				}, {
					type: 'image',
					src: 'http://cdn.yic3.cn/lawyer/mp-xhs/guide/icon24.png'
				}],
				success(res) {
					console.log(res)
				},
				fail(err) {
					console.log(err)
				}
			})
			// #endif

		},
		onShow() {
			this.getUserInfo()
		},
		methods: {
			...mapActions({
				getUserInfo: 'getUserInfo'
			}),
			goRoutePage(url) {
				// #ifdef APP
				if (this.userInfo.guest) {
					this.goRoute('/packageA/pages/login/login')
				} else {
					this.goRoute(url)
				}
				// #endif
				// #ifdef MP
				this.goRoute(url)
				// #endif

			},
			toPath(e) {
				if (e.path == '/pages/dialog/dialog') return this.goItemDetail(e.path)
				if (e.name == '联系客服') {
					this.goServer()
				} else if (e.html) {
					this.goHtml(e.path)
				} else {
					this.goRoute(e.path)
				}
			},
			goServer() {
				// #ifdef APP-PLUS
				let sweixin = null
				let that = this
				const {
					cropid,
					url
				} = uni.getStorageSync('config')['client.center.weixin.service']
				plus.share.getServices(res => {
					sweixin = res.find(i => i.id === 'weixin')
					if (sweixin.id == 'weixin') {
						sweixin.openCustomerServiceChat({
							corpid: cropid, //企业ID
							url: url, //客服链接地址
						}, suc => {
							console.log("success", JSON.stringify(suc))
						}, err => {
							console.log("error", JSON.stringify(err))
						}, )
					} else {
						uni.showToast({
							title: '当前环境不支持微信操作',
							icon: "none"
						});
					}
				}, function() {
					uni.showToast({
						title: "获取服务失败，不支持该操作。" + JSON.stringify(e),
						icon: 'none'
					})
				})
				// #endif
			},
			share() {
				// #ifdef APP
				uni.share({
					provider: 'weixin', //分享服务提供商（即weixin|qq|sinaweibo）
					type: 0, //图文
					scene: 'WXSceneSession', //provider 为 weixin 时必选 WXSceneSession分享到聊天界面，WXSceneTimeline分享到朋友圈，WXSceneFavorite分享到微信收藏
					title: '招标时讯', //分享内容的标题
					summary: '这里有最新最全的标讯，快来看看吧', //分享内容的摘要
					href: 'http://www.baidu.com/', //跳转链接，type 为 0 时必选
					imageUrl: '../../static/shareLogo.png', //图片地址，type 为 0、2、5 时必选
					success(res) {
						//成功返回的参数
						console.log(res);
					},
					fail(err) {
						//失败返回的参数
						console.log(err);
					}
				})
				// #endif
			}
		}

	}
</script>

<style lang="scss" scoped>
	@import 'mine.scss'
</style>
<style>
	page {
		background-color: #18171D;
	}
</style>